package mlz.a_address;

import java.net.InetAddress;
import java.net.UnknownHostException;

/*
    常用方法
 */
public class InetAddresDemo {
    public static void main(String[] args) throws UnknownHostException {
        //1.获取本机IP地址对象
        InetAddress ip1 = InetAddress.getLocalHost();
        String name = ip1.getHostName();
        System.out.println(name);//DESKTOP-NH6MO2V
        System.out.println(ip1.getHostAddress());//192.168.56.1

        //2.获取指定IP或者域名的IP地址对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getHostName());//www.baidu.com
        System.out.println(ip2.getHostAddress());//192.168.56.1
    }
}







